﻿@{
    Layout = null;
    ViewBag.Title = "管理收货地址";
    var list = ViewData["list"] as List<Pay.DTO.shippingaddress_dto>;
}
<html>

<head>
    <meta charset="UTF-8">
    <title>管理收货地址</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
    <meta name="format-detection" content="telphone=no, email=no" />
    <meta name="full-screen" content="yes">
    <meta name="x5-fullscreen" content="true">
    <meta name="msapplication-tap-highlight" content="no">
    <link href="~/Content/css/reset.css" rel="stylesheet" />
    <link href="~/Content/css/swiper.min.css" rel="stylesheet" />
    <link href="~/Content/css/gelunbu.css" rel="stylesheet" />

    <script src="~/Content/js/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/Content/js/layer/1.9.3/layer.js"></script>
    <script type="text/javascript">
        function del(id) {
			layer.load(1);
            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/User/Delete",//url
                data: { Id: id },
                success: function (result) {
					layer.closeAll('loading');
                    if (result.code<0) {
                        layer.msg(result.msg);
                    } else if(result.code == 1000) {
                        window.location.reload();
                    }
                },
                error: function () {
                    layer.msg("异常！");
                }
            });
        }
        function SetDefault(id) {
            var storage = window.localStorage;
           
            layer.confirm('您确定要修改默认地址？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/User/SetDefault/",//url
                    data: { Id: id},
                    success: function (result) {
                      
                        if (result.code == -1) {
                            layer.msg(result.msg);
                        } else {
                            window.location.reload();
                        }
                    },
                    error: function () {
                        layer.msg("异常！");
                    }
                });
                layer.msg('的确很重要', { icon: 1 });
                }, function () {
                    //this.close();
            });
        }
    </script>
</head>

<body style="background: #f0f0f0;">
    <div class="add_new_addr">
        @if (list != null && list.Count > 0) {
        foreach (var item in list) {
            <div class="select_addr_list mt">
                <div class="selet_name">
                    收货人： @item.shipto <span class="phone">@item.phone</span>
                </div>
                <p class="select_addr_detail">地址：@(item.region.region_name + " " + item.address)</p>

                <div class="sf_num">
                    <i class="icon_sf"></i>@item.id_card
                </div>

                <div class="select_addres">
                    <div class="select_addr_active">
                        @if (item.is_default == true) {
                        <input type="checkbox" id="check" name="check1" checked><label for="check1">默认地址</label>
                } else {
                    <input type="checkbox" id="check" name="check1" onchange="SetDefault('@item.id')"><label for="check1">默认地址</label>
            }

                    </div>

                    <div class="select_del">
                        <i class="icon_del" onclick="del('@item.id')"></i>删除
                    </div>

                </div>

            </div>
    }
}
        <a href="/User/AddAddress" class="finish_btn">添加新地址</a>

    </div>
   
</body>

</html>